package com.qianfeng.gl4study.youshare.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.qianfeng.gl4study.youshare.R;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * 主界面下方的九宫格
 * Created with IntelliJ IDEA.
 * I'm glad to share my knowledge with you all.
 * User:Gaolei
 * Date:2015/2/4
 * Email:pdsfgl@live.com
 */
public class GridViewBaseAdapter extends BaseAdapter {

	private Context context;
	private LinkedList<Map<String, ?>> data;
	private int layoutId;

	public GridViewBaseAdapter(Context context, LinkedList<Map<String, ?>> data, int layoutId) {
		this.context = context;
		this.data = data;
		this.layoutId = layoutId;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(layoutId, parent, false);
		ImageView imageView = (ImageView)view.findViewById(R.id.item_enter_point_icon);
		LinearLayout linearLayout = (LinearLayout)view.findViewById(R.id.item_point_bg);
		TextView textView = (TextView) view.findViewById(R.id.item_enter_point_title);
		Map<String, Integer> map = (Map<String, Integer>)data.get(position);
		linearLayout.setBackgroundResource(map.get("bg"));
		imageView.setImageResource(map.get("icon"));
		textView.setText(map.get("title"));
		return view;
	}
}
